// Copyright 2008 web2me.dev
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package net.web2me.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.web2me.api.CommonConstants;
import net.web2me.api.ParsersNamesConstants;

public class ParsersComboActionListener implements ActionListener {
	
	private List<String> defaultUrls = new ArrayList<String>();
	
	private JPanel context;

	public ParsersComboActionListener(JPanel context) {
		this.context = context;
		
		defaultUrls.add("http://imagefap.com/gallery/#");
		defaultUrls.add("http://fotolog.com/user");
		defaultUrls.add("http://clublez.com/movies/lesbian_movie_scenes/");
	}

	public void actionPerformed(ActionEvent e) {
		JTextField urlField = (JTextField) context.getComponent(Web2MeGuiSwing.URL_FIELD);
		
		JComboBox parsersCombo = (JComboBox) context.getComponent(Web2MeGuiSwing.PARSER_COMBO);
		String parser = parsersCombo.getSelectedItem().toString();
		
		if(!urlField.getText().equals(CommonConstants.HTTP_DOT_DOT_SLASH_SLASH) && 
			!defaultUrls.contains(urlField.getText())	) {
			return;
		}
		
		if(ParsersNamesConstants.IMAGEFAP.equals(parser)) {
			urlField.setText(defaultUrls.get(0));
		} else if(ParsersNamesConstants.UBBI_FOTOLOG.equals(parser)) {
			urlField.setText(defaultUrls.get(1));
		} else if(ParsersNamesConstants.CLUBLEZ.equals(parser)) {
			urlField.setText(defaultUrls.get(2));
		} else {
			urlField.setText(CommonConstants.HTTP_DOT_DOT_SLASH_SLASH);
		}
	}

}
